import Vue from 'vue'

import Cookies from 'js-cookie'

import Element from 'element-ui'
import './assets/styles/element-variables.scss'

import '@/assets/styles/index.scss' // global css
import '@/assets/styles/basic.scss' // basic css
import App from './App'
import store from './store'
import router from './router'
import directive from './directive' // directive
import plugins from './plugins' // plugins

import './assets/icons' // icon
import './permission' // permission control
import { getDicts } from "@/api/system/dict/data";
import { getConfigKey } from "@/api/system/config";
import { parseTime, resetForm, addDateRange, selectDictLabel, selectDictLabels, handleTree, diffTime, fileSize, fileSuffixName } from "@/utils/basic";
// 分页组件
import Pagination from "@/components/Pagination";
// 自定义表格工具组件
import RightToolbar from "@/components/RightToolbar"
// 富文本组件
import Editor from "@/components/Editor"
// 文件上传组件
import FileUpload from "@/components/FileUpload"
// 图片上传组件
import ImageUpload from "@/components/ImageUpload"
// 图片预览组件
import ImagePreview from "@/components/ImagePreview"
// 字典标签组件
import DictTag from '@/components/DictTag'
// 头部标签组件
import VueMeta from 'vue-meta'
// 字典数据组件
import DictData from '@/components/DictData'
// socket封装
import webSocketApi from "@/utils/webSocket";
// 文件计算HASH值
import {cutFile} from "@/utils/fileChunk"
// 用户标签组件
import UserTag from "@/components/UserTag";
// 复制组件
import VueClipboard from 'vue-clipboard2';

// 全局方法挂载
Vue.prototype.$getDicts = getDicts
Vue.prototype.$getConfigKey = getConfigKey
Vue.prototype.$parseTime = parseTime
Vue.prototype.$resetForm = resetForm
Vue.prototype.$addDateRange = addDateRange
Vue.prototype.$selectDictLabel = selectDictLabel
Vue.prototype.$selectDictLabels = selectDictLabels
Vue.prototype.$handleTree = handleTree
Vue.prototype.$diffTime = diffTime
Vue.prototype.$fileSize = fileSize
Vue.prototype.$fileSuffixName = fileSuffixName
Vue.prototype.$webSocketApi = webSocketApi;
Vue.prototype.$cutFile = cutFile


// 全局组件挂载
Vue.component('DictTag', DictTag)
Vue.component('Pagination', Pagination)
Vue.component('RightToolbar', RightToolbar)
Vue.component('Editor', Editor)
Vue.component('FileUpload', FileUpload)
Vue.component('ImageUpload', ImageUpload)
Vue.component('ImagePreview', ImagePreview)
Vue.component('UserTag', UserTag)

Vue.use(directive)
Vue.use(VueClipboard);
Vue.use(plugins)
Vue.use(VueMeta)
DictData.install()

// 注册一个自定义指令 -- 移动
Vue.directive('dialog-move',function(el,bingding){
  // 获取需要移动的 dialog 盒子部分
  let moveBox = el.firstElementChild
  // 获取盒子的 header 部分，该部分用做按下移动的功能区域
  let moveElement = el.firstElementChild.firstElementChild
  // 鼠标按下事件
  function mouseDown (e){
    // 鼠标样式变化
    el.style.cursor = 'move'
    // 记录鼠标位置减去盒子距离浏览器之后剩余的距离
    let X = e.clientX - moveBox.offsetLeft
    let Y = e.clientY - moveBox.offsetTop
    function mouseMove(e){
      // 取消自带的margin，避免对移动的影响
      moveBox.style.margin = 'inherit'
      // 拖动
      moveBox.style.top = e.clientY - Y + 'px'
      moveBox.style.left = e.clientX - X + 'px'
    }
    // 鼠标移动
    document.addEventListener('mousemove',mouseMove)

    // 鼠标抬起
    document.addEventListener('mouseup',()=>{
      el.style.cursor = 'auto'
      // 取消监听鼠标移动
      document.removeEventListener('mousemove',mouseMove)
    })
  }
  // 创建鼠标按下监听事件
  moveElement.addEventListener('mousedown',mouseDown)
})
/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online! ! !
 */

Vue.use(Element, {
  size: Cookies.get('size') || 'mini' // set element-ui default size
})

// 表格带有斑马纹
Element.Table.props.stripe = {
  default:true,
  type:Boolean
}

// 表格带有边框
Element.Table.props.border = {
  default:true,
  type:Boolean
}

// 表格高度
Element.Table.props.height.default = '100%'

// dialog全局点击modal关闭
Element.Dialog.props.closeOnClickModal.default = false

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
